package com.lxq.market.servlet;

import com.google.gson.JsonObject;
import com.lxq.market.service.AppService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/update/update_app_category")
public class UpdateAppCategoryServlet extends HttpServlet {

    AppService appService=AppService.getInstance();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String appName = req.getParameter("app_name");
        String appCategory=req.getParameter("app_category");
        boolean changed = appService.changeAppCategory(appName, appCategory);
        JsonObject jsonObject=new JsonObject();
        jsonObject.addProperty("result",changed);
        resp.setContentType("application/json;charset=utf-8");
        resp.getOutputStream().write(jsonObject.toString().getBytes(StandardCharsets.UTF_8));
    }
}
